﻿using CommonLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YouErYuanBLL;
using YouErYuanModels;

namespace YouErYuanManage.Controllers
{
    public class CourseSettingController : Controller
    {
        
        //分页，获取幼儿园列表
        [YouErYuanManage.Filter.IsLogin]
        public string GetCourseList()
        {
            CourseBLL cbll = new CourseBLL();
            int pageIndex = 0;
            int pageSize = 0;
            try
            {
                pageIndex = Convert.ToInt32(Request["pageIndex"]);
                pageSize = Convert.ToInt32(Request["pageSize"]);
            }
            catch (Exception)
            {
                pageIndex = 1;
                pageSize = 10;
            }
            string schoolid = (HttpContext.Session["user"] as Teacher).Schoolid;
            string date = Request["date"];
            int total = 0;
            object dt = cbll.CourseSettingPageList(date, pageIndex, pageSize, schoolid, out total);
            int pageCount = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;//总页数
            var data = new
            {
                pageIndex = pageIndex,
                pageCount = pageCount,
                list = dt,
                total = total
            };
            return CommonMethod.FormatJsonObj("", data);
        }
        /// <summary>
        /// 获取科目数据
        /// </summary>
        /// <returns></returns>
        public string GetSubject()
        {
            CourseBLL cbll = new CourseBLL();
            object dt = cbll.SubjectList();
            return CommonMethod.FormatJsonObj("", dt);
        }
        /// <summary>
        /// 新增或修改
        /// </summary>
        /// <returns></returns>
        [YouErYuanManage.Filter.IsLogin]
        public string InsertOrUpdate()
        {
            CourseBLL cbll = new CourseBLL();
            Course course = new Course();
            string type = Request["type"];
            course.id = Request["id"];
            course.schoolId = Request["schoolId"];
            if (string.IsNullOrWhiteSpace(course.schoolId))
                course.schoolId = (HttpContext.Session["user"] as Teacher).Schoolid;
            course.startDate = !string.IsNullOrWhiteSpace(Request["startDate"]) ? DateTime.Parse(Request["startDate"]) : new Nullable<DateTime>();
            course.type = Request["sType"];
            course.courseName = Request["courseName"];
            object count = cbll.InsertOrUpdate(type, course);
            return CommonMethod.FormatJsonObj(count, "");
        }
        /// <summary>
        /// 删除课程
        /// </summary>
        /// <returns></returns>
        public string CourseDel()
        {
            CourseBLL cbll = new CourseBLL();
            Course course = new Course();
            course.id = Request["id"] + "";
            if (course.id == "")
            {
                return CommonMethod.FormatJsonObj("删除失败", "");
            }
            string count = cbll.CourseDel(course) + "";
            return CommonMethod.FormatJsonObj(count, "");
        }
        //
        public object SelectForId()
        {
            CourseBLL cbll = new CourseBLL();
            string id = Request["id"];
            object dt = cbll.Query(id);
            return CommonMethod.FormatJsonObj("", dt);
        }
        /// <summary>
        /// 新增科目
        /// </summary>
        /// <returns></returns>
        public object InsertSubject()
        {
            CourseBLL cbll = new CourseBLL();
            string subjectName = Request["subjectName"];
            object count = cbll.InsertSuject(subjectName);
            return CommonMethod.FormatJsonObj(count, "");
        }
        ////复制本周课程
        //public object CopyCourseInfo()
        //{
        //    CourseBLL cbll = new CourseBLL();
        //    object count = cbll.Cpoy();
        //    return CommonMethod.FormatJsonObj(count, "");
        //}
        //复制本周课程
        public object CopyCourseInfo()
        {
            CourseBLL cbll = new CourseBLL();
            object count = cbll.Cpoy();
            return CommonMethod.FormatJsonObj(count+"", "");
        }
    }
}